#13 new
Paul Cortens

namespaced users/session controllers cause rspec stories to fail.

Reported by Paul Cortens | September 3rd, 2008 @ 04:45 AM

I am using namespaces for both my UsersController and my SessionController.

When I was updating my rspec stories to use the namespaces, I wasn't able to get some to pass.

Lines such as "When she creates a singular admin/admin_sessions ..." would try to post to 'admin'. The '/' was not consumed by the regex.

The following change seemed to fix the problem.

=================================

ra_navigation_steps.rb

When %r{$actor creates an? $resource with $attributes} do |actor, resource, attributes|

attributes = attributes.to_hash_from_story

  • if resource =~ /singular (\w+)/
  • if resource =~ /singular ([\w\/]+)/ resource = $1.downcase.singularize post "/#{resource}", attributes else post "/#{resource.downcase.pluralize}", { resource.downcase.singularize => attributes } end end

Comments and changes to this ticket

  • Paul Cortens

    Paul Cortens September 3rd, 2008 @ 04:48 AM

    Here is a reposting of the code snippet:

    
    ==================================
    ra_navigation_steps.rb
    ==================================
    
      When %r{$actor creates an? $resource with $attributes} do |actor, resource, attributes|
        attributes = attributes.to_hash_from_story
    -    if resource =~ /singular (\w+)/
    +    if resource =~ /singular ([\w\/]+)/
          resource = $1.downcase.singularize
          post "/#{resource}", attributes
        else
          post "/#{resource.downcase.pluralize}", { resource.downcase.singularize => attributes }
        end
      end
    
  • mrflip

    mrflip September 4th, 2008 @ 03:20 PM

    • Tag set to “generated, install, model, nested”

    Thanks for the patch, fix applied.

    Just curious -- can you present the use case for a nested controller? As in, what problem does it solve?

    Would a super-simple three-roles role system (non-activated user, user, admin) meet the same needs, if that came as a separate plugin guaranteed to work simply with restful authentication?

    I've been arguing for some changes that will make this much harder but other things easier.

  • Paul Cortens

    Paul Cortens September 6th, 2008 @ 01:49 PM

    • Assigned user cleared.
    • Tag changed from “generated, install, model, nested” to “generated, install, model, nested, rspec, stories”

    The application I was working on when I found this is a small CMS. It will be used as the basis for several project we have. We thought it would be a little cleaner to have all the CMS/admin code in a namespace. Having nested routes kept in line with it so that when we reference our URLs with admin_my_model_path it is always clear in code that the url is for admin stuff.

    Overall it isn't a super high value use case. If you have changes that add more value then I don't think anyone loses much by not making the change I suggested.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Restful Authentication Generator

This widely-used plugin provides a foundation for securely managing user
authentication:
* Login / logout
* Secure password handling
* Account activation by validating email
* Account approval / disabling by admin
* Rudimentary hooks for authorization and access control.

http://github.com/technoweenie/restful-authentication/tree

People watching this ticket

Pages